
// 设置Cookie
function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
	var expires = "expires=" + d.toGMTString();
	document.cookie = cname + "=" + cvalue + "; " + expires;
}
// 获取Cookie
function getCookie(cname) {
	var name = cname + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i].trim();
		var arrC = c.split("=");
		if (arrC[0] == cname) {
			return arrC[1];
		}
	}
	return "";
}
function countPrice(){
	var obj = {};
	var cart = getCookie("cart");
	if(cart){
		var newGoodsIndex = Number(getCookie("newGoodsIndex"));
		var goodsArr = JSON.parse(cart);
		if (cart) {
			var _price = 0;
			var _goodsNum = 0;
			goodsArr.forEach(function(item) {
				_goodsNum = _goodsNum + item.num;
				_price =_price + Number(item.goodsPrice.replace(/￥/g, "").trim())*item.num;
				obj.price = _price;
				obj.goodsNum = _goodsNum;
				obj.index= newGoodsIndex;
			})
		};
	}
	return obj;
}